package com.zjgsu.demo.Repository;

import com.zjgsu.demo.nodeEntity.Device;

import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;

public interface DeviceRepository extends Neo4jRepository<Device, Long> {
    @Query("MATCH (n:device) WITH n MATCH p=(n)-[*0..1]-(m) RETURN p LIMIT 150 ")
    Iterable<Device> findAll() ;


    Device findDeviceByTitle(@Param("title") String title);

    @Query("MATCH (m:device) WHERE m.title = {title} DELETE m RETURN m")
    Device deleteDeviceByTitle(@Param("title") String title);

    @Query("MATCH (m:device) WITH m MATCH(n:device) WHERE m.title ={deivcetitle1} AND n.title = {deivcetitle2}  CREATE (m)-[r:拥有]->(n) RETURN r")
    void setDeviceRelation(@Param("deivcetitle1") String deivcetitle1,@Param("deivcetitle2") String deivcetitle2  );

    //title模糊搜索
    @Query("MATCH (n:device) WHERE n.title =~ ('.*'+{title}+'.*')    WITH n MATCH p=(n)-[*0..1]-(m) RETURN p")
    Iterable<Device> findDevicesByTitle(@Param("title") String title);
}
